package cn.gmph.blog.service.term;

import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.gmph.blog.service.term.dao.TermRelationshipsDAO;
import cn.gmph.blog.service.term.dao.TermTaxonomyDAO;
import cn.gmph.blog.service.term.dao.TermmetaDAO;
import cn.gmph.blog.service.term.dao.TermsDAO;
import cn.gmph.blog.service.term.entity.TermsDO;
import cn.gmph.core.base.BaseService;
import cn.gmph.core.base.ResultDTO;
import cn.gmph.core.base.ResultPageDTO;

@Service
public class TermsService extends BaseService {

    private Logger               logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private TermsDAO             termsDAO;
    @Autowired
    private TermRelationshipsDAO termRelationshipsDAO;
    @Autowired
    private TermmetaDAO          termmetaDAO;
    @Autowired
    private TermTaxonomyDAO      termTaxonomyDAO;

    // 分页
    public ResultPageDTO<TermsDO> page(TermsDO terms, Integer pageNum, Integer pageSize) {
        logger.info("开始分页查询TermsService.page, terms=" + terms.toString());
        List<TermsDO> pageList = this.termsDAO.pageList(terms, pageNum, pageSize);
        Integer count = this.termsDAO.pageListCount(terms);
        ResultPageDTO<TermsDO> pager = new ResultPageDTO<TermsDO>(count, pageList);
        return pager;
    }

    // 添加
    public TermsDO doAdd(TermsDO terms, int loginUserId) {
        logger.info("开始添加TermsService.add,terms=" + terms.toString());
        this.termsDAO.insert(terms);
        return terms;
    }

    // 修改
    public Integer doUpdate(TermsDO terms, Integer loginUserId) {
        logger.info("开始修改TermsService.update,terms=" + terms.toString());
        int rows = this.termsDAO.update(terms);
        return rows;
    }

    // 删除
    public Integer doDelete(TermsDO terms, Integer loginUserId) {
        logger.info("开始删除TermsService.delete,terms=" + terms.toString());
        int rows = this.termsDAO.deleteById(terms.getTermId());
        return rows;
    }

    // 查询
    public TermsDO doQueryById(Long id) {
        TermsDO obj = this.termsDAO.getById(id);
        return obj;
    }
}